package com.mdd.product.controller;

import com.mdd.common.aop.Log;
import com.mdd.common.aop.NotPower;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.validate.IdValidate;
import com.mdd.product.service.IProductTypeService;
import com.mdd.product.validate.ProductTypeCreateValidate;
import com.mdd.product.validate.ProductTypeUpdateValidate;
import com.mdd.product.vo.ProductTypeListedVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("api/type")
@Api(tags = "车品类别管理")
public class ProductTypeController {

    @Resource
    IProductTypeService iProductTypeService;

    @NotPower
    @GetMapping("/list")
    @ApiOperation(value="车品类别列表")
    public AjaxResult<List<ProductTypeListedVo>> list() {
        return AjaxResult.success(iProductTypeService.list());
    }
    @NotPower
    @Log(title = "车品类别新增")
    @PostMapping("/add")
    @ApiOperation(value="车品类别新增")
    public AjaxResult<Object> add(@Validated @RequestBody ProductTypeCreateValidate createValidate) {
        iProductTypeService.add(createValidate);
        return AjaxResult.success();
    }
    @NotPower
    @Log(title = "车品类别编辑")
    @PostMapping("/edit")
    @ApiOperation(value="车品类别编辑")
    public AjaxResult<Object> edit(@Validated @RequestBody ProductTypeUpdateValidate updateValidate) {
        iProductTypeService.edit(updateValidate);
        return AjaxResult.success();
    }
    @NotPower
    @Log(title = "车品类别删除")
    @PostMapping("/del")
    @ApiOperation(value="车品类别删除")
    public AjaxResult<Object> del(@Validated @RequestBody IdValidate idValidate) {
        iProductTypeService.del(idValidate.getId());
        return AjaxResult.success();
    }

}
